﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;

namespace Phoenix
{
    public partial class Details : System.Web.UI.Page
    {
        Phoenix.AppCode.Entities.Article details = new Phoenix.AppCode.Entities.Article();
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie fenix_lang = Request.Cookies["Culture"];
            if (fenix_lang == null)
            {
                LoadDB_US();
            }
            else
            {
                if (fenix_lang.Value == "vi-VN")
                {
                    LoadDB_VN();
                }
                else
                {
                    LoadDB_US();
                }
            }
        }
        private void LoadDB_VN()
        {
            int id = int.Parse(Request.QueryString["Id"].ToString());
            string lang = "vi-VN";
            details.ID_Article = id;
            details.Language = lang;
            DataTable dt = Phoenix.AppCode.Bussiness.ArticleService.ArticleDetails(details);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                lb_title.Text = dr["TitleName"].ToString();
                text_content.Text = dr["Content"].ToString();

                string dtitle = dr["TitleName"].ToString();
                string htitle = dr["TitleHead"].ToString();
                string des = dr["DescriptionHead"].ToString();
                string key = dr["KeywordHead"].ToString();
                HtmlHead headTag = (HtmlHead)this.Header;
                if (htitle.Length < 2)
                {
                    headTag.Title = dtitle;
                }
                else
                {
                    headTag.Title = htitle;
                }
                HtmlMeta PagemetaTag = new HtmlMeta();
                PagemetaTag.Name = "description";
                PagemetaTag.Content = des;
                headTag.Controls.Add(PagemetaTag);

                PagemetaTag = new HtmlMeta();
                PagemetaTag.Name = "keywords";
                PagemetaTag.Content = key;
                headTag.Controls.Add(PagemetaTag);
            }
            else { Response.Redirect("Default.aspx"); }
        }
        private void LoadDB_US()
        {
            int id = int.Parse(Request.QueryString["Id"].ToString());
            string lang = "en-US";
            details.ID_Article = id;
            details.Language = lang;
            DataTable dt = Phoenix.AppCode.Bussiness.ArticleService.ArticleDetails(details);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                lb_title.Text = dr["TitleName"].ToString();
                text_content.Text = dr["Content"].ToString();

                string dtitle = dr["TitleName"].ToString();
                string htitle = dr["TitleHead"].ToString();
                string des = dr["DescriptionHead"].ToString();
                string key = dr["KeywordHead"].ToString();
                HtmlHead headTag = (HtmlHead)this.Header;
                if (htitle.Length < 2)
                {
                    headTag.Title = dtitle;
                }
                else
                {
                    headTag.Title = htitle;
                }
                HtmlMeta PagemetaTag = new HtmlMeta();
                PagemetaTag.Name = "description";
                PagemetaTag.Content = des;
                headTag.Controls.Add(PagemetaTag);

                PagemetaTag = new HtmlMeta();
                PagemetaTag.Name = "keywords";
                PagemetaTag.Content = key;
                headTag.Controls.Add(PagemetaTag);
            }
            else { Response.Redirect("Default.aspx"); }
        }
    }
}